/**
 * A publisher to push updates to subscribing methods
 * @version 1.0
 */
var Publisher = function () {
	this.subscribers = [];
};
/**
 * Add a method to the subscribers array
 * @param {Function} that Reference to a subscribing method.
 */
Publisher.prototype.add = function (that) {
	if (typeof that === 'function') {
		for (var i = 0, len = this.subscribers.length; i < len; i += 1) {
			if (this.subscribers[i] === that) {
				return;
			}
		}
		this.subscribers.push(that);		
	}
};
/**
 * Remove a method from the subscribers array
 * @param {Funciton} that Reference to an unsubscribing method.
 */
Publisher.prototype.remove = function (that) {
	if (typeof that === 'function') {
		for (var i = 0, len = this.subscribers.length; i < len; i += 1) {
			if (this.subscribers[i] === that) {
				this.subscribers.splice(i, 1);
			}
		}
	}
};
/**
 * Method to call when data should be pushed to subscribers
 * @param {Any} data Data to push to subscribers
 */
Publisher.prototype.deliver = function (data) {
	for (var i = 0, len = this.subscribers.length; i < len; i += 1) {
		this.subscribers[i](data);
	}
	return this;
};

/**
 * Add method to publishers subscriber list
 * @param {Function} publisher Pointer to publisher
 */
Function.prototype.subscribe = function (publisher) {
	publisher.add(this);
	return this;
};
/**
 * Remove method from publishers subscriber list
 * @param {Function} publisher Pointer to publisher
 */
Function.prototype.unsubscribe = function (publisher) {
	publisher.remove(this);
	return this;
};
